package com.stylefeng.guns.rest.modular.film.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.stylefeng.guns.api.film.service.FilmAsyncServiceAPI;
import com.stylefeng.guns.api.film.vo.ActorVO;
import com.stylefeng.guns.api.film.vo.FilmDescVO;
import com.stylefeng.guns.api.film.vo.ImgVO;
import com.stylefeng.guns.rest.common.persistence.dao.MoocActorTMapper;
import com.stylefeng.guns.rest.common.persistence.dao.MoocFilmInfoTMapper;
import com.stylefeng.guns.rest.common.persistence.model.MoocActorT;
import com.stylefeng.guns.rest.common.persistence.model.MoocFilmInfoT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @创建人 lIUJF
 * @创建时间 2019/1/8
 * @描述:
 */
@Component
@Service(interfaceClass = FilmAsyncServiceAPI.class)
public class DefaultFilmAsyncServiceImpl implements FilmAsyncServiceAPI {
	@Autowired
	private MoocFilmInfoTMapper moocFilmInfoTMapper;
	@Autowired
	private MoocActorTMapper moocActorTMapper;


	@Override
	public FilmDescVO getFilmDesc(String filmId) {

		MoocFilmInfoT moocFilmInfoT = getFilmInfo(filmId);

		FilmDescVO filmDescVO = new FilmDescVO();
		filmDescVO.setBiography(moocFilmInfoT.getBiography());
		filmDescVO.setFilmId(filmId);

		return filmDescVO;
	}

	@Override
	public ImgVO getImgs(String filmId) {

		MoocFilmInfoT moocFilmInfoT = getFilmInfo(filmId);
		// 图片地址是五个以逗号为分隔的链接URL
		String filmImgStr = moocFilmInfoT.getFilmImgs();
		String[] filmImgs = filmImgStr.split(",");

		ImgVO imgVO = new ImgVO();
		imgVO.setMainImg(filmImgs[0]);
		imgVO.setImg01(filmImgs[1]);
		imgVO.setImg02(filmImgs[2]);
		imgVO.setImg03(filmImgs[3]);
		imgVO.setImg04(filmImgs[4]);

		return imgVO;
	}

	@Override
	public ActorVO getDectInfo(String filmId) {

		MoocFilmInfoT moocFilmInfoT = getFilmInfo(filmId);

		// 获取导演编号
		Integer directId = moocFilmInfoT.getDirectorId();

		MoocActorT moocActorT = moocActorTMapper.selectById(directId);

		ActorVO actorVO = new ActorVO();
		actorVO.setImgAddress(moocActorT.getActorImg());
		actorVO.setDirectorName(moocActorT.getActorName());

		return actorVO;
	}

	@Override
	public List<ActorVO> getActors(String filmId) {
		List<ActorVO> actors = moocActorTMapper.getActors(filmId);
		return actors;
	}

	private MoocFilmInfoT getFilmInfo(String filmId){
		MoocFilmInfoT moocFilmInfoT = new MoocFilmInfoT();
		moocFilmInfoT.setFilmId(filmId);
		moocFilmInfoT = moocFilmInfoTMapper.selectOne(moocFilmInfoT);
		return moocFilmInfoT;
	}

}
